<template>
  <div class="_wz_cent_main _wz_sendNotice">
    <Card :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="通知标题">
          <i-input v-model="formDataSearch.noticeTitle" placeholder="通知标题搜索" clearable />
        </FormItem>
        <FormItem label="回复状态">
          <i-select v-model.number="formDataSearch.noticeReplyType" filterable placeholder="请选择回复状态" clearable>
            <Option :value="0">无需回复</Option>
            <Option :value="1">需要回复</Option>
          </i-select>
        </FormItem>
        <FormItem label="签收状态" v-if="searchType">
          <i-select v-model.number="formDataSearch.noticeReadState" filterable placeholder="请选择签收状态" clearable>
            <Option :value="0">未签收</Option>
            <Option :value="1">已签收</Option>
          </i-select>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>


    <!--回复-->
    <Drawer v-model="notifyReplyType" title="通知回复" width="700" :draggable="true" @on-visible-change="notifyReplyTypeFun">
      <notifyReply v-if="notifyReplyType" :selectData="selectData" @closeFun="closeFun"></notifyReply>
    </Drawer>


  </div>
</template>
<script>

  import notifyReply from "./notifyReply";
  import wzTbale from "../../../components/table/table";

  export default {
    components: {
      notifyReply,//回复
      wzTbale,//列表
    },
    data() {
      return {
        subDeptList:[],
        searchType:false,//搜索条件
        notifyReplyType: false,//回复
        selectData: {},
        formDataSearch: {},//搜索表单数据
        tableData: {
          url: this.apiUrl.noticeOrgMessageNoticeOrgMessageRecordPageList,//请求地址
          method: 'post',//请求方式
          where: {},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 80, align: 'center', title: '序号'},
            {title: '通知标题', key: 'noticeTitle', minWidth: 160,},
            {
              title: '通知等级', minWidth: 130, render: (h, params) => {
                // 通知消息等级：1：普通，2：重要，3：紧急
                if (params.row.noticeLv == 1) {
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '普通')
                } else if (params.row.noticeLv == 2) {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '重要')
                } else {
                  return h('Tag', {props: {type: 'dot',color: 'error'}}, '紧急')
                }
              }
            },
            {title: '通知时间', key: 'publishTime', minWidth: 160,},
            {
              title: '截止时间', width: 160, render: (h, params) => {
                if(!!params.row.noticeEndTime){
                  return h('span', params.row.noticeEndTime)
                }else{
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '不限时')
                }
              }
            },
            {
              title: '签收时间', width: 160, render: (h, params) => {
                if(!!params.row.readTime){
                  return h('span', params.row.readTime);
                }else{
                  return h('Tag', {props: {type: 'dot',color: 'error'}}, '未签收');
                }
              }
            },
            {
              title: '回复时间', width: 160, render: (h, params) => {
                if (params.row.noticeReplyType == 0) { //0：未回复，1：已回复
                  return h('Tag', { props: {type: 'dot', color: 'success'}}, '无需回复');
                } else {
                  if (!!params.row.replyTime) {
                    return h('span', params.row.replyTime);
                  } else {
                    return h('Tag', {props: {type: 'dot',color: 'error'}}, '未回复');
                  }
                }
              }
            },

            {
              title: '操作', width: 100, fixed: 'right',
              render: (h, params) => {
                let operationButtons = [];
                operationButtons.push(h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row));
                      this.notifyReplyType = true;
                    }
                  }
                }, !!params.row.readTime?'查看':'签收'))
                return operationButtons;
              }
            },
            {title: '下发机构', key: 'orgName', minWidth: 140,},
            {title: '下发人', key: 'orgName', minWidth: 140,},
            {title: '运输企业', key: 'deptName', minWidth: 220,},
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },

      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态
    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      var that = this;
      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
        if (!!res) {
          that.subDeptList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })

    },
    methods: {//执行的方法
      //添加修改触发后关闭刷新
      closeFun(data) {
        if (data) {//添加修改 刷新表单
          this.$refs.wzTbale.tableLoadData();
        }
        this.notifyReplyType = false;
      },
      //搜索
      searchSubmit() {//搜索
        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },
      //关闭刷新
      notifyReplyTypeFun() {
        if (this.selectData.noticeReadState == 0) {
          this.$refs.wzTbale.tableLoadData();
        }
      },
    },
    watch: {//监听

    },
    props: {//接收来自父组件的数据

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>


<style lang="less">
  ._wz_sendNotice {
    height: 100%;
    display: flex;
    flex-direction: column;
  }
</style>
